package com.tuju.jetpackfirstdemo.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RadialGradient;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.view.ViewGroup;

public class CircleGroupView extends ViewGroup {

    public CircleGroupView(Context context) {
        super(context);
        initPaint();
    }

    public CircleGroupView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initPaint();
    }

    public CircleGroupView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initPaint();
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {

    }

    private Paint circlePaint;
    private Paint mSquePaint;
    private Paint linePaint;

    private void initPaint() {
        //方形遮挡
        mSquePaint = new Paint();
        mSquePaint.setColor(Color.parseColor("#253460"));
//        mSquePaint.setColor(Color.BLUE);
//        mSquePaint.setStrokeWidth(20f);
        mSquePaint.setStyle(Paint.Style.FILL);

        //原型边框
        circlePaint = new Paint();
        circlePaint.setStrokeWidth(20f);
        circlePaint.setStyle(Paint.Style.STROKE);

        //扫描线
        linePaint = new Paint();
        linePaint.setStrokeWidth(2f);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
//        Shader radialShader = new RadialGradient((getWidth() / 2), (getHeight() / 2), (getWidth() / 2), Color.parseColor("#43DE95"),
//                Color.parseColor("#0043DE95"), Shader.TileMode.CLAMP);
//        linePaint.setShader(radialShader);
//
//        Shader linearShader = new LinearGradient(0f, (getHeight() / 2), getWidth(), (getHeight() / 2), Color.parseColor("#43DE95"),
//                Color.parseColor("#24BF92"), Shader.TileMode.CLAMP);
//        circlePaint.setShader(linearShader);

        Path path = new Path();
        path.addCircle(getWidth() / 2, getHeight() / 2, getWidth() / 2, Path.Direction.CW);
        path.addRect(0, 0, getWidth(), getHeight(), Path.Direction.CW);
        path.setFillType(Path.FillType.EVEN_ODD);

        canvas.drawPath(path, mSquePaint);
//        canvas.drawCircle(getWidth() / 2, getHeight() / 2, getWidth() / 2, circlePaint);
    }
}
